package com.yuyou.tas.admin.handler;

import java.net.InetAddress;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import com.yuyou.tas.admin.service.ICommKeyConfigService;


@Component
public class ActuatorHealthHandler implements HealthIndicator {
 
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	@Autowired
	private ICommKeyConfigService commKeyConfigService;
	
	@Override
	public Health health() {
		
		try{
			InetAddress addr = InetAddress.getLocalHost();  
	    	//1.redis
	    	stringRedisTemplate.opsForValue().set(addr.getHostName()+":tas_admin_health", String.valueOf(System.currentTimeMillis()));
	    	//2.mysql
	    	commKeyConfigService.selectByDataKey("1");
	    	return new Health.Builder(Status.UP).build();
			}catch(Exception e){
				return new Health.Builder(Status.DOWN).build();
			}
		

	}
 
}